﻿using System;
using System.Linq;
using SapaFinance.Domain.Model;
using Xunit;

namespace SapaFinance.Tests
{
    public class BankTest
    {
        internal static Bank Create()
        {
            var bank = new Bank("БИК", "корреспондентсткий счет", "Название банка", UserTest.Create());
            bank.Swift="уник. номер банка в мире";
            return bank;
        }

        [Fact]
        public void CheckAccountOpen()
        {
            var corporation = CorporationTest.Create();
            var user = UserTest.Create();
            var bank = Create();
            corporation.OpenAccount("45345345345", new Usd(), bank, user);
            Assert.Equal(1, corporation.Accounts.Count);
            var account = corporation.Accounts.First();
            Assert.NotNull(account);
            Assert.Equal(bank, account.Bank);
            Assert.Equal(new Usd(), account.Currency);
            Assert.Equal(CorporationTest.Create(), account.Corporation);
            Assert.Null(account.Iban);
            Assert.Equal("45345345345", account.Number);
            var z = new Account("45345345345", new Usd(), bank,corporation, user);
            Assert.Equal(z, account);
        }

        [Fact]
        public void CheckAccountOpenWithIBAN()
        {
            var corporation = CorporationTest.Create();
            var user = UserTest.Create();
            var bank = Create();
            corporation.OpenAccount("45345345345", new Usd(), bank, user);
            var account1 = corporation.Accounts.First();
            account1.Iban = "5345345345";
            corporation.ChangeAccount(account1);
            Assert.Equal(1, corporation.Accounts.Count);
            var account = corporation.Accounts.First();
            Assert.NotNull(account);
            Assert.Equal(bank, account.Bank);
            Assert.Equal(new Usd(), account.Currency);
            Assert.Equal(CorporationTest.Create(), account.Corporation);
            Assert.Equal("5345345345", account.Iban);
            Assert.Equal("45345345345", account.Number);
            var z = new Account("45345345345", new Usd(),bank,corporation, user);
            z.Iban="5345345345";
            Assert.Equal(z, account);
        }

        [Fact]
        public void CheckBankCreate()
        {
            var bank = Create();
            var bank1 = Create();
            Assert.NotNull(bank);
            Assert.Equal("Название банка", bank.Name);
            Assert.Equal("БИК", bank.Bin);
            Assert.Equal("корреспондентсткий счет", bank.CorrespondentAccount);
            Assert.Equal("уник. номер банка в мире", bank.Swift);
            Assert.Equal(bank1, bank);
            bank1.Name="wefwefwef";
            Assert.Equal(bank1, bank);
            bank1.Bin="новый уник номер банка";
            Assert.NotEqual(bank1, bank);

        }

    }
}